﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;

namespace DataModels.Models
{
    public class TestingAndCounselingData
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [StringLength(50)]
        [Required]
        [ForeignKey("Facility")]
        [Column(TypeName = "varchar")]
        public string FacilityCode { get; set; }
        public Facility Facility { get; set; }

        [ForeignKey("Timeframe")]
        public int TimeframeId { get; set; }
        public virtual Timeframe Timeframe { get; set; }

        [ForeignKey("CounselingAndTesting")]
        public int CounselingAndTestingId { get; set; }

        public virtual TestingAndCounseling CounselingAndTesting { get; set; }

        public Nullable<int> UserId { get; set; }

        [ForeignKey("UserId")]
        public virtual User User { get; set; }

        public Nullable<DateTime> DateCreated { get; set; }

        public int TC01_MaleLT15 { get; set; }
        public int TC01_MaleGT15 { get; set; }
        public int TC01_FemaleLT15 { get; set; }
        public int TC01_FemaleGT15 { get; set; }

        public int TC02_MaleLT15 { get; set; }
        public int TC02_MaleGT15 { get; set; }
        public int TC02_FemaleLT15 { get; set; }
        public int TC02_FemaleGT15 { get; set; }

        public int TC03_MaleLT15 { get; set; }
        public int TC03_MaleGT15 { get; set; }
        public int TC03_FemaleLT15 { get; set; }
        public int TC03_FemaleGT15 { get; set; }

        public int TC04_MaleLT15 { get; set; }
        public int TC04_MaleGT15 { get; set; }
        public int TC04_FemaleLT15 { get; set; }
        public int TC04_FemaleGT15 { get; set; }

        public int TC05_MaleLT15 { get; set; }
        public int TC05_MaleGT15 { get; set; }
        public int TC05_FemaleLT15 { get; set; }
        public int TC05_FemaleGT15 { get; set; }

        public int TC06_MaleLT15 { get; set; }
        public int TC06_MaleGT15 { get; set; }
        public int TC06_FemaleLT15 { get; set; }
        public int TC06_FemaleGT15 { get; set; }

        public int TC07_MaleLT15 { get; set; }
        public int TC07_MaleGT15 { get; set; }
        public int TC07_FemaleLT15 { get; set; }
        public int TC07_FemaleGT15 { get; set; }

        public int TC08_MaleLT15 { get; set; }
        public int TC08_MaleGT15 { get; set; }
        public int TC08_FemaleLT15 { get; set; }
        public int TC08_FemaleGT15 { get; set; }

        public int TC09_MaleLT15 { get; set; }
        public int TC09_MaleGT15 { get; set; }
        public int TC09_FemaleLT15 { get; set; }
        public int TC09_FemaleGT15 { get; set; }

        public int TC10_MaleLT15 { get; set; }
        public int TC10_MaleGT15 { get; set; }
        public int TC10_FemaleLT15 { get; set; }
        public int TC10_FemaleGT15 { get; set; }

        public int TC11_MaleLT15 { get; set; }
        public int TC11_MaleGT15 { get; set; }
        public int TC11_FemaleLT15 { get; set; }
        public int TC11_FemaleGT15 { get; set; }

        public int TC12_MaleLT15 { get; set; }
        public int TC12_MaleGT15 { get; set; }
        public int TC12_FemaleLT15 { get; set; }
        public int TC12_FemaleGT15 { get; set; }

        public static TestingAndCounselingData operator +(TestingAndCounselingData d1, TestingAndCounselingData d2)
        {
            var result = new TestingAndCounselingData();
            if (d1.FacilityCode == d2.FacilityCode)
            {
                result.FacilityCode = d1.FacilityCode;
                if (d1.Facility != null) result.Facility = d1.Facility;
                if (d2.Facility != null) result.Facility = d2.Facility;
            }

            if (d1.TimeframeId == d2.TimeframeId)
            {
                result.TimeframeId = d1.TimeframeId;
                if (d1.Timeframe != null) result.Timeframe = d1.Timeframe;
                if (d2.Timeframe != null) result.Timeframe = d2.Timeframe;
            }

            if (d1.CounselingAndTestingId == d2.CounselingAndTestingId)
            {
                result.CounselingAndTestingId = d1.CounselingAndTestingId;
                if (d1.CounselingAndTesting != null) result.CounselingAndTesting = d1.CounselingAndTesting;
                if (d2.CounselingAndTesting != null) result.CounselingAndTesting = d2.CounselingAndTesting;
            }

            result.TC01_FemaleGT15 = d1.TC01_FemaleGT15 + d2.TC01_FemaleGT15;
            result.TC01_FemaleLT15 = d1.TC01_FemaleLT15 + d2.TC01_FemaleLT15;
            result.TC01_MaleGT15 = d1.TC01_MaleGT15 + d2.TC01_MaleGT15;
            result.TC01_MaleLT15 = d1.TC01_MaleLT15 + d2.TC01_MaleLT15;

            result.TC02_FemaleGT15 = d1.TC02_FemaleGT15 + d2.TC02_FemaleGT15;
            result.TC02_FemaleLT15 = d1.TC02_FemaleLT15 + d2.TC02_FemaleLT15;
            result.TC02_MaleGT15 = d1.TC02_MaleGT15 + d2.TC02_MaleGT15;
            result.TC02_MaleLT15 = d1.TC02_MaleLT15 + d2.TC02_MaleLT15;

            result.TC03_FemaleGT15 = d1.TC03_FemaleGT15 + d2.TC03_FemaleGT15;
            result.TC03_FemaleLT15 = d1.TC03_FemaleLT15 + d2.TC03_FemaleLT15;
            result.TC03_MaleGT15 = d1.TC03_MaleGT15 + d2.TC03_MaleGT15;
            result.TC03_MaleLT15 = d1.TC03_MaleLT15 + d2.TC03_MaleLT15;

            result.TC04_FemaleGT15 = d1.TC04_FemaleGT15 + d2.TC04_FemaleGT15;
            result.TC04_FemaleLT15 = d1.TC04_FemaleLT15 + d2.TC04_FemaleLT15;
            result.TC04_MaleGT15 = d1.TC04_MaleGT15 + d2.TC04_MaleGT15;
            result.TC04_MaleLT15 = d1.TC04_MaleLT15 + d2.TC04_MaleLT15;

            result.TC05_FemaleGT15 = d1.TC05_FemaleGT15 + d2.TC05_FemaleGT15;
            result.TC05_FemaleLT15 = d1.TC05_FemaleLT15 + d2.TC05_FemaleLT15;
            result.TC05_MaleGT15 = d1.TC05_MaleGT15 + d2.TC05_MaleGT15;
            result.TC05_MaleLT15 = d1.TC05_MaleLT15 + d2.TC05_MaleLT15;

            result.TC06_FemaleGT15 = d1.TC06_FemaleGT15 + d2.TC06_FemaleGT15;
            result.TC06_FemaleLT15 = d1.TC06_FemaleLT15 + d2.TC06_FemaleLT15;
            result.TC06_MaleGT15 = d1.TC06_MaleGT15 + d2.TC06_MaleGT15;
            result.TC06_MaleLT15 = d1.TC06_MaleLT15 + d2.TC06_MaleLT15;

            result.TC07_FemaleGT15 = d1.TC07_FemaleGT15 + d2.TC07_FemaleGT15;
            result.TC07_FemaleLT15 = d1.TC07_FemaleLT15 + d2.TC07_FemaleLT15;
            result.TC07_MaleGT15 = d1.TC07_MaleGT15 + d2.TC07_MaleGT15;
            result.TC07_MaleLT15 = d1.TC07_MaleLT15 + d2.TC07_MaleLT15;

            result.TC08_FemaleGT15 = d1.TC08_FemaleGT15 + d2.TC08_FemaleGT15;
            result.TC08_FemaleLT15 = d1.TC08_FemaleLT15 + d2.TC08_FemaleLT15;
            result.TC08_MaleGT15 = d1.TC08_MaleGT15 + d2.TC08_MaleGT15;
            result.TC08_MaleLT15 = d1.TC08_MaleLT15 + d2.TC08_MaleLT15;

            result.TC09_FemaleGT15 = d1.TC09_FemaleGT15 + d2.TC09_FemaleGT15;
            result.TC09_FemaleLT15 = d1.TC09_FemaleLT15 + d2.TC09_FemaleLT15;
            result.TC09_MaleGT15 = d1.TC09_MaleGT15 + d2.TC09_MaleGT15;
            result.TC09_MaleLT15 = d1.TC09_MaleLT15 + d2.TC09_MaleLT15;

            result.TC10_FemaleGT15 = d1.TC10_FemaleGT15 + d2.TC10_FemaleGT15;
            result.TC10_FemaleLT15 = d1.TC10_FemaleLT15 + d2.TC10_FemaleLT15;
            result.TC10_MaleGT15 = d1.TC10_MaleGT15 + d2.TC10_MaleGT15;
            result.TC10_MaleLT15 = d1.TC10_MaleLT15 + d2.TC10_MaleLT15;

            result.TC11_FemaleGT15 = d1.TC11_FemaleGT15 + d2.TC11_FemaleLT15;
            result.TC11_FemaleLT15 = d1.TC11_FemaleLT15 + d2.TC11_FemaleLT15;
            result.TC11_MaleGT15 = d1.TC11_MaleGT15 + d2.TC11_MaleGT15;
            result.TC11_MaleLT15 = d1.TC11_MaleLT15 + d2.TC11_MaleLT15;

            result.TC12_FemaleGT15 = d1.TC12_FemaleGT15 + d2.TC12_FemaleGT15;
            result.TC12_FemaleLT15 = d1.TC12_FemaleLT15 + d2.TC12_FemaleLT15;
            result.TC12_MaleGT15 = d1.TC12_MaleGT15 + d2.TC12_MaleGT15;
            result.TC12_MaleLT15 = d1.TC12_MaleLT15 + d2.TC12_MaleLT15;

            return result;
        }
    }
}
